package org.dromara.iot.domain;

import cn.hutool.core.date.DateUtil;
import lombok.Data;
import org.dromara.iot.domain.bo.IotElevatorEventBo;
import org.dromara.iot.enums.DeviceElevatorEventTypeEnum;
import org.dromara.iot.enums.DoorStatusEnum;
import org.dromara.iot.enums.ElectricVehicleStatusEnum;

import java.util.Date;

/**
 * 设备事件信息
 */
@Data
public class DeviceEvent {
    /**
     * 事件类型
     */
    private DeviceElevatorEventTypeEnum event;

    /**
     * 事件ID
     */
    private String eventid;

    /**
     * 电瓶车状态
     */
    private ElectricVehicleStatusEnum motostatus;

    /**
     * 人员数量
     */
    private int personcount;

    /**
     * 门状态
     */
    private DoorStatusEnum dooropen;

    /**
     * 设备ID
     */
    private String devid;

    /**
     * 随机数
     */
    private String nonce;

    /**
     * 时间戳
     */
    private int timestamp;

    /**
     * 签名
     */
    private String sign;

    /**
     * 电梯状态信息
     */
    private Elevstatus elevstatus;

    /**
     * AC信息
     */
    private Acinfo acinfo;

    public IotElevatorEventBo toIotElevatorEvent() {
        IotElevatorEventBo iotElevatorEventBo = new IotElevatorEventBo();
        iotElevatorEventBo.setEventType(event.getCode());
        iotElevatorEventBo.setEventCode(eventid);
        iotElevatorEventBo.setDoorStatus(dooropen.getCode());
        iotElevatorEventBo.setMotorcycleStatus(motostatus.getCode());
        iotElevatorEventBo.setPersonCount(personcount);
        iotElevatorEventBo.setDeviceId(devid);
        iotElevatorEventBo.setReportTime(new Date());
        iotElevatorEventBo.setNonce(nonce);
        iotElevatorEventBo.setSignature(sign);
        iotElevatorEventBo.setLevelingStatus(elevstatus.getLevelingstatus().getCode());
        iotElevatorEventBo.setRunSpeed(elevstatus.getSpeed());
        iotElevatorEventBo.setAirPressure(elevstatus.getPress());
        iotElevatorEventBo.setCurrentFloor(elevstatus.getElevactpos());
        iotElevatorEventBo.setFloorName(elevstatus.getElevname());
        iotElevatorEventBo.setAcOperationCount(acinfo.getAcelevtimes());
        iotElevatorEventBo.setAcOpenCount(acinfo.getAcelevtimes());
        iotElevatorEventBo.setAcMileage(acinfo.getAcmile());
        iotElevatorEventBo.setAcRunDuration(acinfo.getActime());
        iotElevatorEventBo.setAbnormalSound(acinfo.getAcelevtimes());
        iotElevatorEventBo.setEmergencyStop(acinfo.getAcelevtimes());
        return iotElevatorEventBo;
    }
}
